package paper.graph;
import java.awt.Color;
import paper.db.PaperIndex;
import paper.db.Paper;

/* To define a new Vertex class for a PaperGraph simply extend
   this base class. Ensure that you provide a toString() method
   that generates label="<visible dot name>" if you plan to 
   generate dot/neato output from the graph. You MUST override
   the copy method otherwise things will go bad. You MUST
   override the makeDefault method otherwise things are bad.
*/
public class Vertex
{
    public String key;
    public Color colour;
    public String toString()
    {
        return "label=\"" + key + "\",style=filled,fillcolor=\"" + 
               colString() + "\"";
    }
    public String toString(PaperIndex index)
    {
        if( index==null )
            return toString();
        Paper p = index.findKey(key);
        if( p==null )
            return toString();
        return  "label=\"" + p.flatTitle + "\",style=filled,fillcolor=\"" + colString() + "\"";
    }

    String colDigs(int comp)
    {
        String rawDigs = Integer.toHexString( comp );
        if( rawDigs.length() == 1 )
            return "0" + rawDigs;
        return rawDigs;
    }

    String colString()
    {
        return "#" + 
               colDigs( colour.getRed() ) +
               colDigs( colour.getGreen() ) +
               colDigs( colour.getBlue() );
    }
    public Vertex(String x)
    {
        key = x;
        colour = Color.BLACK;
    }
    public Vertex copy()
    {
        Vertex x = new Vertex(key);
        x.colour = colour;
        return x;
    }
    static public Vertex makeDefault(String s)
    {
        return new Vertex(s);
    }
}

